home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Messaging Service Access Module / Internet PMSAM / Internet PMSAM source / errorhandling.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-29  |  5.5 KB  |  252 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------
  2.  
  3. AOCE Post Office Protocol (POP) / Simple Mail Transfer Protocol (SMTP)
  4. Mail Service Access Module
  5.  
  6. written by Steve Falkenburg-- MacDTS
  7. ©1991-1993 Apple Computer, Inc.
  8.  
  9. --------------
  10. change history
  11. --------------
  12.  
  13. SJF        02/19/93    update for beta build    b1
  14. SJF        10/29/92    update to a11            a11
  15. SJF        06/08/92    update to a8            a8
  16. SJF        02/15/92    first working version    a4.5
  17. SJF        10/16/91    initial coding            a3
  18.  
  19. ---------------------------------------------------------------------*/
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24.  
  25. #ifndef __PACKAGES__
  26. #include <Packages.h>
  27. #endif
  28.  
  29. #ifndef __OCE__
  30. #include <OCE.h>
  31. #endif
  32.  
  33. #ifndef __OCEMAIL__
  34. #include <OCEMail.h>
  35. #endif
  36.  
  37. #ifndef __OCEERRORS__
  38. #include <OCEErrors.h>
  39. #endif
  40.  
  41. #include <MacTCPCommonTypes.h>
  42.  
  43. #include "const.h"
  44. #include "gwerrors.h"
  45. #include "mytypes.h"
  46. #include "globals.h"
  47. #include "utils.h"
  48. #include "gatewaystuff.h"
  49.  
  50. #include "errorhandling.h"
  51.  
  52. #define    kFirstTCPError        -23049
  53. #define    kLastTCPError        -23000
  54.  
  55. #define    kFirstAOCEError        -1999
  56. #define    kLastAOCEError        -1500
  57. #define    kFirstAOCEErrorToo    -15199
  58. #define    kLastAOCEErrorToo    -15000
  59.  
  60.  
  61. void DoError(OSErr err)
  62. {
  63.     MailErrorLogEntryInfo ml;
  64.     PMSAMLogErrorPB msamBlock;
  65.     MSAMSlotID slotID;
  66.     SlotSpec *slotSpec;
  67.  
  68. #ifdef kDEBUG
  69.     DebugStr("\pAN ERROR HAS OCCURRED");
  70. #endif
  71.     
  72.     if (gAOCEInited==false) {
  73.         NoAOCEError(err);
  74.         return;
  75.     }
  76.     
  77.     slotSpec = GetSlotSpecFromID(1);
  78.     
  79.     slotID = 0;    // non-slot specific
  80.     ml.version = kMailErrorLogEntryVersion;
  81.     ml.errorType = 0;
  82.     ml.errorCode = 0;
  83.     ml.errorResource = 0;
  84.     ml.actionResource = 0;
  85.  
  86.     if (err>=kFirstTCPError && err<=kLastTCPError) {
  87.         // MACTCP ERROR (warning)
  88.         ml.errorType = kMailELEWarning;
  89.         ml.errorCode = kMailMSAMErrorCode;
  90.         ml.errorResource = kMacTCPError;
  91.         if (slotSpec)
  92.             slotID = slotSpec->slotID;    // we only have 1 slot- make it easy on ourselves
  93.     }
  94.     else if (((err>=kFirstAOCEError) && (err<=kLastAOCEError)) ||
  95.              ((err>=kFirstAOCEErrorToo) && (err<=kLastAOCEErrorToo))) {
  96.         // AOCE ERROR (warning)
  97.         ml.errorType = kMailELEWarning;
  98.         ml.errorCode = kMailMSAMErrorCode;
  99.         ml.errorResource = kAOCEError;
  100.     }
  101.     else if ((err>=kFirstNonCorrectableError) && (err<=kLastNonCorrectableError)) {
  102.         // NON-CORRECTABLE ERROR (error)
  103.         ml.errorType = kMailELEError;
  104.         ml.errorCode = kMailMSAMErrorCode;
  105.         ml.errorResource = err;
  106.     }
  107.     else if ((err>=kFirstCorrectableError) && (err<=kLastCorrectableError)) {
  108.         // CORRECTABLE ERROR (correctable)
  109.         ml.errorType = kMailELECorrectable;
  110.         ml.errorCode = kMailMSAMErrorCode;
  111.         ml.errorResource = err;
  112.         ml.actionResource = err;
  113.         if (err!=kMacTCPNotAvailable)
  114.             if (slotSpec)
  115.                 slotID = slotSpec->slotID;    // we only have 1 slot- make it easy on ourselves
  116.     }
  117.     else {
  118.         // MISC TOOLBOX ERRORS (warning)
  119.         ml.errorType = kMailELEWarning;
  120.         ml.errorCode = kMailMSAMErrorCode;
  121.         ml.errorResource = kToolboxError;
  122.     }
  123.     
  124.     msamBlock.logEntry = &ml;
  125.     msamBlock.msamSlotID = slotID;
  126.     
  127.     err = PMSAMLogError((MSAMParam *)&msamBlock);
  128. #ifdef kDEBUG
  129.     if (err!=noErr)
  130.         DebugStr("\pERROR LOG FAILED");
  131. #endif
  132. }
  133.  
  134.  
  135. void NoAOCEError(OSErr err)
  136. {
  137.     Str255 errStr;
  138.     Str255 errNumStr;
  139.     
  140.     if (err==noErr)
  141.         return;
  142.     
  143.     if (err>0)
  144.         GetIndString(errNumStr,128,err);    // positive errors indicate specific app errors
  145.     else
  146.         NumToString(err,errNumStr);
  147.         
  148.     pstrcpy(errStr,"\pAn error has occurred: ");
  149.     pstrcat(errStr,errNumStr);
  150.     
  151. #ifdef kDEBUG
  152.     DebugStr(errStr);
  153. #endif
  154.  
  155.     Notify(errStr);
  156.  
  157. }
  158.  
  159.  
  160. void Notify(StringPtr string)
  161. {
  162.     NMRecPtr nm;
  163.     StringPtr strPtr;
  164.     
  165.     nm = (NMRecPtr)NewPtrSys(sizeof(NMRec));    // put in system heap, since we're going away
  166.     if (MemError()!=noErr)
  167.         return;
  168.     strPtr = (StringPtr)NewPtrSys(string[0]);
  169.     if (MemError()!=noErr)
  170.         return;
  171.     BlockMove(string,strPtr,string[0]+1);
  172.     
  173.     nm->qType = nmType;
  174.     nm->nmMark = 0;
  175.     nm->nmIcon = nil;
  176.     nm->nmSound = nil;
  177.     nm->nmStr = strPtr;
  178.     nm->nmResp = (NMProcPtr)-1L;    // close enough for memory deallocation, otherwise we need to copy code into sys heap.
  179.     NMInstall(nm);
  180. }
  181.  
  182.  
  183. // used to track error retries on a slot
  184. //
  185. // if you exceed the number of retries allowed on the same error, this
  186. // function will report the error to the toolbox, otherwise, it will
  187. // track the retries until you reach the maximum
  188. //
  189. OSErr RetrySlotError(OSErr err,SlotSpec *slot,Boolean forPut)
  190. {
  191.     if (err==noErr) {
  192.         // reset counters if no error
  193.         if (forPut) {
  194.             slot->retryPutError = noErr;
  195.             slot->retryPut = 0;
  196.         }
  197.         else {
  198.             slot->retryGetError = noErr;
  199.             slot->retryGet = 0;
  200.         }
  201.     }
  202.     else {
  203.         
  204. #ifdef kDEBUG
  205.     DebugStr("\pAN ERROR HAS OCCURRED");
  206. #endif
  207.  
  208.         if (forPut) {
  209.             if (slot->retryPutError!=err) {
  210.                 // need to report *both* errors here, since they are different
  211.                 // old error is reported directly, new error through return
  212.                     if (slot->retryPutError!=noErr)
  213.                         DoError(slot->retryPutError);
  214.                     slot->retryPut = 0;
  215.                     slot->retryPutError = err;
  216.             }
  217.             else
  218.                 slot->retryPut++;
  219.             
  220.             // have we passed max retries?
  221.             
  222.             if (slot->retryPut >= kAllowedRetries) {
  223.                 slot->retryPutError = noErr;
  224.                 slot->retryPut = 0;
  225.             }
  226.             else
  227.                 err = noErr;
  228.         }
  229.         else {
  230.                 if (slot->retryGetError!=err) {
  231.                 // need to report *both* errors here, since they are different
  232.                 // old error is reported directly, new error through return
  233.                     if (slot->retryGetError!=noErr)
  234.                         DoError(slot->retryGetError);
  235.                     slot->retryGet = 0;
  236.                     slot->retryGetError = err;
  237.             }
  238.             else
  239.                 slot->retryGet++;
  240.             
  241.             // have we passed max retries?
  242.             
  243.             if (slot->retryGet >= kAllowedRetries) {
  244.                 slot->retryGetError = noErr;
  245.                 slot->retryGet = 0;
  246.             }
  247.             else
  248.                 err = noErr;
  249.         }    
  250.     }
  251.     return err;
  252. }